<%= form_for @image, url: (@url_override or @image.persisted? ? refinery.admin_image_path(@image) : refinery.admin_images_path),
             html: { multipart: true } do |f| %>

  <%= render '/refinery/admin/error_messages',
             object: @image,
             include_object_name: false %>

  <%= render '/refinery/admin/locale_picker', :current_locale => Globalize.locale if @image.persisted? %>

  <div class="field">
    <% if action_name =~ /(edit)|(update)/ %>
      <p>
        <%= t('.use_current_image') %>
        <em><%= t('.or') %></em><%= t('.replace_image') %>
      </p>
      <p>
        <%= f.file_field :image %>
      </p>
    <% else %>
      <% # we must only hint at multiple when it's a new record otherwise update fails. %>
      <%= f.file_field :image, multiple: true %>
    <% end %>
  </div>

  <div class="field">
    <label><%= t('.maximum_image_size', bytes: number_to_human_size(Refinery::Images.max_image_size)) %></label>
  </div>
  <div class="field" id="title">
    <span class='label_with_help'>
      <%= f.label :image_title, t('.image_title') %>
      <%= refinery_help_tag t('.image_title_help') %>
    </span>
    <%= f.text_field :image_title, placeholder: t('.image_title') %>
  </div>

  <div class="field" id="alt">
    <span class='label_with_help'>
      <%= f.label :image_alt, t('.image_alt') %>
      <%= refinery_help_tag t('.image_alt_help') %>
    </span>
    <%= f.text_field :image_alt, placeholder: t('.image_alt') %>
  </div>

  <input type="hidden" name="wymeditor" value="<%= params[:wymeditor] %>">

  <%= render '/refinery/admin/form_actions', f: f,
             continue_editing: false,
             hide_cancel: (@app_dialog or action_name == 'insert' or from_dialog?),
             delete_title: t('delete', scope: 'refinery.admin.images'),
             delete_confirmation: t('message', scope: 'refinery.admin.delete', title: @image.image_name),
             cancel_url: refinery.admin_images_path -%>

  <% if @app_dialog %>
    <input type="hidden" name="app_dialog" value="<%= @app_dialog %>" />
    <input type="hidden" name="field" value="<%= @field %>" />
    <input type="hidden" name="update_image" value="<%= @update_image %>" />
    <input type="hidden" name="thumbnail" value="<%= @thumbnail %>" />
    <input type="hidden" name="callback" value="<%= @callback %>" />
    <input type="hidden" name="conditions" value="<%= @conditions %>" />
  <% end %>
<% end %>

<% if action_name =~ /(edit)|(update)/ %>
  <div id="existing_image">
    <label><%=t('.current_image') %></label>
    <%= image_fu @thumbnail || @image, '225x255>', class: 'brown_border' %>
  </div>
<% end %>
